<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>审批流状态管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" />
<link rel="stylesheet" href="/static/ui/css/ui.css" />
</head>

<body>
    <form class="layui-form" action="" lay-filter="editform">
        <div class="mainBox">
            <div class="main-container">
                <div class="main-container">
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" lay-verify="required|len" autocomplete="off" min="1"
                                placeholder="请输入状态名称" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态颜色</label>
                        <div class="layui-input-block">
                            <input type="radio" name="color" checked value="layui-btn layui-btn-primary" title="原始白">
                            <input type="radio" name="color" value="layui-btn" title="提示绿">
                            <input type="radio" name="color" value="layui-btn layui-btn-normal"  title="百搭蓝">
                            <input type="radio" name="color" value="layui-btn layui-btn-warm"  title="暖色黄">
                            <input type="radio" name="color" value="layui-btn layui-btn-danger"  title="警告红">
                            <input type="radio" name="color" value="layui-btn layui-btn-disabled"  title="禁用灰">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">操作用户</label>
                        <div class="layui-input-block">
                            <div id="user-area" class="xm-select-demo"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发我消息</label>
                        <div class="layui-input-inline" style="width:500px">
                            <input type="text" name="my_msg" lay-verify="required" id="my_msg" autocomplete="off" min="1"
                                placeholder="发我的消息，例如：您有新的消息需要审核了" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <i class="layui-icon layui-icon-fonts-clear" 
                             onclick="copy('您有新的消息需要审核了','my_msg')"></i>  
                         </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">通过消息</label>
                        <div class="layui-input-inline" style="width:500px">
                            <input type="text" name="to_msg" id="to_msg" lay-verify="required" autocomplete="off" min="1"
                                placeholder="通过的消息，例如：您的申请被{{username}}审核通过了" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <i class="layui-icon layui-icon-fonts-clear" 
                             onclick="copy('您的申请被{{username}}审核通过了','to_msg')"></i>  
                         </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">驳回消息</label>
                        <div class="layui-input-inline" style="width:500px">
                            <input type="text" name="back_msg" lay-verify="required"
                            autocomplete="off" min="1" id="back_msg"
                                placeholder="驳回的消息，例如：您的申请被{{username}}打回了" class="layui-input">  
                        </div>
                        <div class="layui-input-inline">
                           <i class="layui-icon layui-icon-fonts-clear" 
                            onclick="copy('您的申请被{{username}}打回了','back_msg')"></i>  
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">通过规则</label>
                        <div class="layui-input-block">
                            <input type="radio" name="pass_type" value="0" title="严格模式" checked>
                            <input type="radio" name="pass_type" value="1" title="一票通过">
                            <input type="radio" name="pass_type" value="2" title="少数服从多数">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">打回规则</label>
                        <div class="layui-input-block">
                            <input type="radio" name="back_type" value="0" title="严格模式" checked>
                            <input type="radio" name="back_type" value="1" title="一票否决">
                            <input type="radio" name="back_type" value="2" title="少数服从多数">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">钉钉通知</label>
                        <div class="layui-input-block">
                            <input type="radio" name="ding_notice" value="0" title="不通知" checked>
                            <input type="radio" name="ding_notice" value="1" title="通知">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <textarea name="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <input type="hidden" name="id" />
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="approve-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
            </div>
        </div>
    </form>
    <script src="../config.js"></script>
    <script src="/static/layui/layui.js"></script>
    <script src="/static/ui/ui.js"></script>
    <script src="/static/utils/xm-select.js"></script>
    <script src="../utils/select.js"></script>
    <script>
        layui.use(['form', 'layer', 'tree'], function () {
            let form = layui.form
                , layer = layui.layer
                , $ = layui.$
                , req = _req()
                , aid = req.aid
                , id = req.id;
            form.verify({
                len: (val, item) => {
                    let min = item.getAttribute("min")
                    if (val.length < min) {
                        return '长度不能小于' + min;
                    }
                }
            })
            if (req.id) {
                //渲染
                _get(layui, 'approve/statusEditBefore?id=' + req.id, res => {
                    getElSelect(res.userList, res.user_list, 'user-area', 'checkbox', false, { name: 'user_list',layVerify: 'required', layVerType: 'tips' });
                    form.val('editform', res)
                });
            }else{
                _get(layui, 'approve/statusAddBefore', res => {
                    getElSelect(res.userList, '', 'user-area', 'checkbox', false, { name: 'user_list',layVerify: 'required', layVerType: 'tips' });
                });
            }
            window.copy = function(msg, el) {
                $("#" + el).val(msg)
            }
            //监听提交
            form.on('submit(approve-save)', function (data) {
                data = data.field;
                let postUrl;
                if (req.id) {
                    postUrl = 'approve/statusEdit';
                } else {
                    postUrl = 'approve/statusAdd';
                    data.aid = aid;
                }
                _post(layui, postUrl, data, res => {
                    //console.log(res)
                    parent.layui.table.reload("status-table");
                    parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页

                })

                return false;
            });

        });
    </script>

</body>

</html>